<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/css/x-admin.css" media="all">
</head>

<body>

<div class="x-body">
        	  <form class="layui-form" method="post" action="/system/user/doEdit">
                      <div class="layui-form-item">
                          <label for="username" class="layui-form-label">
                              <span class="x-red">*</span>用户名
                          </label>
                          <div class="layui-input-inline">
                              <input type="hidden" id ="id" value="${sysUser.id}" name="id">
                              <input type="text" id="userName" name="userName" value="${(sysUser.userName)!}" required="" lay-verify="required"
                                     autocomplete="off" class="layui-input">
                          </div>
                          <div class="layui-form-mid layui-word-aux">
                              <span class="x-red">*</span>您唯一的登入名
                          </div>
                      </div>
                      <div class="layui-form-item">
                          <label for="deptId" class="layui-form-label">
                              <span class="x-red">*</span>部门
                          </label>
                          <div class="layui-input-inline">
                              <select id="deptId" name="deptId" required="" lay-verify="required">
                                  <#list deptList as dept>
                                      <option value="${(dept.id)!}" <#if sysUser.deptId?? && dept.id==sysUser.deptId> selected="selected" </#if> >${(dept.deptName)!}</option>
                                  </#list>
                              </select>
                          </div>
                      </div>

                      <div class="layui-form-item">
                          <label for="password" class="layui-form-label">
                              <span class="x-red">*</span>密码
                          </label>
                          <div class="layui-input-inline">
                              <input type="password" id="password" name="password" disabled="disabled" value="********" required="" lay-verify="pass"
                                     autocomplete="off" class="layui-input">
                          </div>
                          <div class="layui-form-mid layui-word-aux">
                              6到16个字符
                          </div>
                      </div>
                      <div class="layui-form-item">
                          <label for="roleId" class="layui-form-label">
                              <span class="x-red">*</span>角色
                          </label>
                          <div class="layui-input-inline">
                              <select id="roleId" name="roleId" required="" lay-verify="required">
                                  <#list sysRoles as role>
                                      <option value="${(role.id)!}" <#if myRolds?seq_contains('${role.id}') > selected="selected" </#if>>${(role.roleName)!}</option>
                                  </#list>
                              </select>
                          </div>
                      </div>
                      <div class="layui-form-item">
                          <label for="userDesc" class="layui-form-label">描述</label>
                          <div class="layui-input-block">
                          <textarea class="layui-textarea" id="userDesc" name="userDesc"
                          placeholder="请输入描述，最多300个字符 ...">${(sysUser.userDesc)!}</textarea>
                          </div>
                      </div>
                      <div class="layui-form-item">
                          <label class="layui-form-label">是否启用</label>
                          <div class="layui-input-block">
                              <input type="radio" id="userState" name="userState" value="1" title="启用" <#if sysUser.userState = 1> checked </#if>>
                              <input type="radio" id="userState" name="userState" value="-1" title="禁用" <#if sysUser.userState = -1> checked </#if>>
                          </div>
                      </div>
                      <div class="layui-form-item">
                          <div class="layui-input-block">
                              <button class="layui-btn" lay-submit lay-filter="save">保存</button>
                          </div>
                      </div>
	          </form>
</div>
<script src="/lib/layui/layui.js" charset="utf-8">
</script>
<script src="/js/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form()
                ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function(value){
                if(value.length < 5){
                    return '昵称至少得5个字符啊';
                }
            }
        });

        //监听提交
        form.on('submit(save)', function(data){
            $.ajax({
                url:"/system/user/doEdit",
                dataType:"json",
                data:{
                    id:$("#id").val(),
                    userName:$("#userName").val(),
                    deptId:$("#deptId").val(),
                    password:$("#password").val(),
                    password2:$("#password2").val(),
                    roleId:$("#roleId").val(),
                    userDesc:$("#userDesc").val(),
                    userState:$('input:radio:checked').val(),
                },
                type:"POST",
                async:false,
                success:function (res) {
                    if(res.meta.success){
                        layer.alert("编辑成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg("增加失败", {icon: 1});
                    }
                },
                error:function (XMLHttpRequest) {
                    layer.msg("系统错误", {icon: 1});
                }
            })
            return false;
        });


    });
</script>
</body>
</html>